<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: LJQ <liujiqi@etrol.com> 
// +----------------------------------------------------------------------

namespace app\service\controller;

use app\common\controller\Admin;
use app\service\controller\api\Reliefcase as ReliefcaseApi;
use app\admin\controller\ajax\Library as Ajax;

/**
 * 救援案例管理
 * @package app\Reliefcase
 */
class Reliefcase  extends Admin

{
    
    protected $api;
    
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new ReliefcaseApi();
            $this->ajax= new Ajax();
	}
    /**
     * 首页
     * 
     */
   	public function index() {
   	  if(IS_AJAX){
   	  	$reliefcaseList = $this->api->reliefcaseList();
   	  	return $reliefcaseList;
   	  }

 
      return $this->fetch();
 	}

 	/**
 	 * 搜索救援案例
 	 */
 	public function search($keyword) {
 		if(IS_AJAX){
			$reliefcaseList = $this->api->search(input('keyword'));
 			return $reliefcaseList;
 		}
 	}
    /**
     * 上传救援案例
     * 
     */
    public function add() {
   		 if(IS_POST){
   		 	$data = input('post.');  
   		 	//有效性
                   if(isset($data['isValid'])){
                     $data['isValid'] = 1;
                     }else{
                       $data['isValid'] = 0;
                     }
                    $data['operationId']=session('user_auth.id');
                    $getfile=$data['pathInfo'];
                    $data['end']=substr($getfile,strrpos($getfile,'.')+1);

                  return $this->api->add($data);
   		 }
           $type=$this->ajax->getDocumentLevelId()->getData();
         
           $this->assign('type',$type);
          
           return $this->fetch();    
     }
 
    /**
     * 修改救援案例
     * 
     */
    public function edit($reliefcaseId = null) {
      
    	  if(IS_POST){
    	  	$data = input('post.');
                  //有效性
                       if(isset($data['isValid'])){
                     $data['isValid'] = 1;
                     }else{
                       $data['isValid'] = 0;
                     }
                    $data['operationId']=session('user_auth.id');
                    if ($data['pathInfo']) {
                      $getfile=$data['pathInfo'];
                      $data['end']=substr($getfile,strrpos($getfile,'.')+1);
                    }
    	       	return $this->api->edit($data,$reliefcaseId);
    	  }
     	  $reliefcaseList = $this->api->reliefcaseList($reliefcaseId)->getData();
         $type=$this->ajax->getDocumentLevelId()->getData();
         $this->assign('type',$type);
     	  $this->assign('info',$reliefcaseList['data'][0]);
         return $this->fetch();      
    }
    
    /**
     * 删除救援案例
     */
    public function del($reliefcaseId = null) {
    	if(IS_AJAX){
    		return $this->api->del($reliefcaseId);
    	}
    }
  }



